package edu.hrbu.spring.controller;

import edu.hrbu.spring.pojo.Admin;
import edu.hrbu.spring.service.AdminService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author 徐登宇
 */
@Controller
public class AdminController {

    @Resource(name = "adminServiceImpl")
    AdminService adminService;

    @RequestMapping("/to/login")
    public String toLogin() {
        return "login";
    }

    @RequestMapping("/login")
    public String login(HttpServletRequest request,
                        @RequestParam("adminName") String adminName,
                        @RequestParam("adminPwd") String adminPwd) {

        Admin admin = adminService.login(adminName, adminPwd);
        if (admin==null) return "redirect:/to/login";
//        System.out.println("@@@@"+admin);
        request.getSession().setAttribute("adminName",admin.getAdminName());
        return "redirect:/dept/list";
    }

}
